home *** CD-ROM | disk | FTP | other *** search
- /* This module keeps the time in the menu bar
- We are going to use the time manager however the header file in
- version 1 is incorrect. We will make the correct declarations here.
- ( version two headers fixed the problem)
-
- Jerry LeVan
- 325 Boone Trail
- Richmond Ky 40475
-
- */
-
- #include <windows.h>
- #include <events.h>
- #include <OSUtils.h>
-
- /* MPW InLine Function/Procs */
-
- pascal void SetUpA51() extern 0x2f0d; /* move.l a5,-(sp) */
- pascal void SetUpA52() extern 0x2a78; /* move.l $904,a5 */
- pascal void SetUpA53() extern 0x0904; /* literal $904 */
-
- #define SetUpA5() \
- SetUpA51(); \
- SetUpA52(); \
- SetUpA53()
-
- pascal void RestoreA5() extern 0x2a5f; /* move.l (sp)+,a5 */
-
- /* MPW timer queue definitions */
-
- typedef struct TMTask {
- struct QElem *qLink;
- short qType;
- ProcPtr tmAddr;
- short tmCount;
- } TMTask;
- pascal void InsTime(tmTaskPtr)
- TMTask *tmTaskPtr;
- extern ;
- pascal void PrimeTime(tmTaskPtr,count)
- TMTask *tmTaskPtr;
- long count;
- extern ;
- pascal void RmvTime(tmTaskPtr)
- TMTask *tmTaskPtr;
- extern ;
-
- Boolean showClock = true; /* if true show the time in menubar */
- static TMTask clockTsk = {0, drvQType, 0, 0 }; /* actually timer queue */
- static GrafPort screen; /* we can draw on the entire screen using this port */
-
- /*************************routines*********************************/
-
- /* the routine should not do anything to "move" memory */
- void clockTimer() /* simply post an event */
- { EventRecord event;
- /* post event only if none are in the queue */
- /* Debugger(); */
- if(!OSEventAvail(app2Mask,&event)) PostEvent(app2Evt,0);
- }
-
- pascal void TimerInterrupt()
- {
- SetUpA5(); clockTimer(); RestoreA5();
- }
-
- void startClock()
- {
- clockTsk.tmAddr = TimerInterrupt;
- InsTime(&clockTsk);
- PrimeTime(&clockTsk,1000); /* and schedule the routine 1 second */
- };
-
- void stopClock()
- { GrafPtr oldPort;
-
- RmvTime(&clockTsk);
- GetPort(&oldPort); /* save current port */
- SetPort(&screen);
- MoveTo(450,14);
- DrawString(" ");
- SetPort(oldPort);
-
- };
-
- void InitClock()
- {
- OpenPort(&screen);
- TextMode(srcCopy);
- if(showClock)startClock();
- }
- void showTime()
- {
- long secs; /* current time */
- DateTimeRec date;
- char dateString[10];
- GrafPtr oldPort; /* temp storage */
-
- GetPort(&oldPort);
- SetPort(&screen);
- ReadDateTime(&secs);
- Secs2Date(secs, &date);
- if(date.hour>12) date.hour -= 12;
- /* convert date record to c string */
- dateString[0] = (date.hour / 10) + 48;
- if(dateString[0] == 48)dateString[0]=' ';
- dateString[1] = (date.hour % 10) + 48;
- dateString[2] = ':';
- dateString[3] = date.minute /10 +48;
- dateString[4] = date.minute % 10 + 48;
- dateString[5] = ':';
- dateString[6] = date.second /10 +48;
- dateString[7] = date.second % 10 +48;
- dateString[8] = 0;
- MoveTo(450,14);
-
- /* the interrupt routine can't do this because drawstring may
- move memory
- */
- DrawString(dateString);
- SetPort(oldPort);
- /* If I rearm here it works */
- PrimeTime(&clockTsk,1000);
- };
-
-